Skip to content

queries(rust): add scope for mutable variables#14353

Closed
nik-rev wants to merge 2 commits intohelix-editor:masterfrom
nik-contrib:highlight-rust-mutable
Closed

queries(rust): add scope for mutable variables#14353
nik-rev wants to merge 2 commits intohelix-editor:masterfrom
nik-contrib:highlight-rust-mutable

Conversation

@nik-rev
Copy link
Contributor

@nik-rev nik-rev commented Aug 31, 2025

test file:

fn foo() {
    let mut a = 100;
}

split up #13932

test file:

```rs
fn foo() {
    let mut a = 100;
}
```

split up helix-editor#13932
[
(let_declaration
(mutable_specifier)
pattern: (identifier) @local.definition.variable.mutable @variable.mutable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both here and #14352 you should only write local.definition.*, local.scope, local.reference or throwaway captures in the locals.scm file, not highlight captures. I think it's necessary to make some highlights work currently but it's a bug in locals if it's required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious - why is it a bug?

anyway, I have "fixed" this by just duplicating the query. I wish there was a more elegant solution

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The locals.scm queries should be separate from highlights and ideally have separate precedence too, so you could hypothetically say

; All parameters are variable.parameter
(parameter) @local.definition.variable.parameter
; Except builtins
((parameter) @_self (#eq? @_self "self"))

Ideally you should also not need to duplicate the highlights between locals.scm and highlights.scm: the locals should take precedence when they match. This needs a bit of work in tree-house to get right.

@nik-rev nik-rev requested a review from the-mikedavis August 31, 2025 13:27
@nik-rev nik-rev closed this Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants